function content0LoadFunction() {
	x_getCurrentEvents(renderCurrentEvents);
	
	var dateStart = new Ext.form.DateField({
	    name: 'eDateStart',
	    width:150,
	    allowBlank:false,
	    format: 'm/d/Y'
	});
	
	var dateEnd = new Ext.form.DateField({
	    name: 'eDateEnd',
	    width: 150,
	    allowBlank:false,
	    format: 'm/d/Y'
	});
	
	dateStart.applyTo('eDateStart');
	dateEnd.applyTo('eDateEnd');
}	

function renderCurrentEvents(string) {
	$('currentEvents').innerHTML = string;
}

function clearForm() {
	$('eCat').options[0].selected = true;
	$('eTitle').value = '';	
	tinyMCE.getInstanceById('eDesc').getBody().innerHTML = '';	
	$('eDateStart').value = eDateStart;
	$('eDateEnd').value = '';
	$('eOnHome').checked = false; 
}

function addEvent() {
	// Turn off add button
	$('buttonNewEvent').style.display = 'none';
	
	// Set formAction to 'add'
	$('formAction').value = 'add';
	
	// Clear form
	clearForm();
	
	// Display add form
	new Effect.SlideDown('formNewEvents', {direction: 'top', duration: .3});
}

function cancelNewEvent() {
	// Display add form
	new Effect.SlideUp('formNewEvents', {direction: 'top', duration: .2});
	// Clear form
	clearForm();
	// Turn on add button
	$('buttonNewEvent').style.display = 'block';	
}

function saveEvent() {
	var eID = $('eID').value;
	var formAction = $('formAction').value;
	var eCat   = $('eCat').options;
	var eCat   = eCat[eCat.selectedIndex].value;
	var eTitle = $('eTitle').value;
	var eDesc  = tinyMCE.getContent(eDesc);
	var eDateStart = $('eDateStart').value;
	var eDateEnd   = $('eDateEnd').value;
	var onHome     = $('eOnHome');
	if (onHome.checked == true) { onHome = 1; }
	else { onHome = 0; }
	
	var phpString  = eCat+'|'+eTitle+'|'+eDesc+'|'+eDateStart+'|'+eDateEnd+'|'+onHome+'|'+eID;
	x_saveEvent(phpString,formAction,returnSaveEvent);	
}

function returnSaveEvent() {
	// Do some post processing here if needed and then...
	
	// Close the add new event form
	cancelNewEvent();
	
	// Render our current events
	x_getCurrentEvents(renderCurrentEvents);
}	

function returnDeleteEvent() {
	x_getCurrentEvents(renderCurrentEvents);
}

function editEvent(eID) {
	x_getEventForEdit(eID,returnGetEventForEdit);
}

function returnGetEventForEdit(string) {
	// Parse string
	stringArray = string.split("|");
	var eID    = stringArray[0];
	var eCat   = stringArray[1];
	var eTitle = stringArray[2];
	var eDesc  = stringArray[3];
	var eDateStart = stringArray[4];
	var eDateEnd   = stringArray[5];
	var onHome     = stringArray[6];
	
	// Populate add/edit form
	
	var eCatOptions = $('eCat').options;
	for(a=0;a<eCatOptions.length;a++) {
		if ($('eCat').options[a].value == eCat) {
			$('eCat').options[a].selected = true;
		}
	}
	
	$('eTitle').value = eTitle;
	
	//tinyMCE.getInstanceById('eDesc');	
	//tinyMCE.setContent(eDesc);
	tinyMCE.getInstanceById('eDesc').getBody().innerHTML = eDesc;	
	$('eDateStart').value = eDateStart;
	$('eDateEnd').value = eDateEnd;
	if (onHome == 1) { $('eOnHome').checked = true; }
	else { $('eOnHome').checked = false; }
	
	// Set formAction to 'edit'
	$('formAction').value = 'edit';
	
	// Set eID
	$('eID').value = eID;
		
	// Turn off add button
	$('buttonNewEvent').style.display = 'none';
	
	// Display add form
	new Effect.SlideDown('formNewEvents', {direction: 'top', duration: .3});
	$('content0').scrollTop = 0;
	
}

function swapOnHome(eID) {
	x_swapOnHome(eID,returnSwapOnHome);
}

function returnSwapOnHome(string) {
	stringArray = string.split("|");
	
	var eID     = stringArray[0];
	var content = stringArray[1];
	
	$('onHomeDiv'+eID).innerHTML = content;
}